﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Net;
using System.Net.Sockets;


namespace RetroNET.Network
{
    public class RNClient
    {
        public Socket sockIn;   // client -> us
        public Socket sockOut;  // us -> destination

		  public byte[] inputbuffer = new byte[1024]; // temp buffer for send / receive of data for this client
		  public byte[] sendbuffer = new byte[1048576]; // temp buffer for sending data over sockOut, larger (1MB) because BBSes can dump a lot of data
		  public byte[] recvbuffer = new byte[1048576]; // temp buffer for receiving data over sockOut, larger (1MB) because BBSes can dump a lot of data

        public StringBuilder recvBufferClient = new StringBuilder(); // Holds the ASCII-encoded commands we've received so we can parse them

        public void Shutdown()
        {
            if (sockIn != null && sockIn.Connected) sockIn.Close();
            if (sockOut != null && sockOut.Connected) sockOut.Close();

        }

        public void ListenToClient(RetroNETCore core)
        {
            sockIn.BeginReceive(inputbuffer, 0, inputbuffer.Length, SocketFlags.None, new AsyncCallback(core.cbReceiveDataFromClient), this);
        }

		  public void SendToDestination(RetroNETCore core)
		  {
			  sockOut.BeginSend(sendbuffer, 0, sendbuffer.Length, SocketFlags.None, new AsyncCallback(core.cbSendClientDataToDestination), this);
		  }

    }

}
